package com.itheima_03;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class StudentTest {
    public static void main(String[] args) throws DocumentException {
        ArrayList<Student> arrayList = new ArrayList<>();
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(new File("day17_demo\\src\\com\\itheima_03\\Student.xml"));
        Element rootElement = document.getRootElement();
        List<Element> studentlist = rootElement.elements("student");
        for (Element element : studentlist) {
            Attribute attribute = element.attribute("id");
            String id = attribute.getValue();
            Element element1 = element.element("name");
            String name = element1.getText();
            String age = element.element("age").getText();
            String birthday = element.element("birthday").getText();
            String sex = element.element("sex").getText();
            Student student = new Student(id,name,Integer.parseInt(age),birthday,sex);
            arrayList.add(student);


        }
        for (Student student : arrayList) {
            System.out.println(student);
        }


    }
}
